﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FindAllProductName1.aspx.cs"
    Inherits="HZ.Supervise.Web.Common.FindAllProductName1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>选择药品</title>
    <link rel="stylesheet" type="text/css" href="../style/global.css" />

    <script type="text/javascript" src="../scripts/jquery.js"></script>

    <script type="text/javascript" src="../scripts/mainlistSelect.js"></script>

    <script type="text/javascript" src="../scripts/Common.js"></script>

    <script type="text/javascript" src="../scripts/global.js"></script>

    <script type="text/javascript" language="javascript">
        function addAreaInfo() {
            var AreaInfo;
            ProInfo = document.getElementById("ProName").value + "|" + document.getElementById("ProId").value;
            window.opener.insertProInfo(ProInfo);
            window.close();
        }

        function chkAllCompany() {
            CheckBoxList = document.getElementsByName("chkPro");
            for (var i = 0; i < CheckBoxList.length; i++) {
                CheckBoxList[i].checked = true;
            }
        }


        function insertCompanyInfo() {

            //            if (!checkSelectedItems('gvwProList', '请至少选择一项！')) {
            //                return false;
            //            }
            //
            //            CheckBoxList = document.getElementsByName("chkPro");

            var hidCheck = document.getElementById("hidCheck"); //得到隐藏控件

            if (hidCheck.value.length <= 0) {
                alert("请至少选择一项！");
                return false;
            }

            var hidCheckArray = hidCheck.value.split(',');

            var resultValue = "";
            var hosNames = "";
            var hosIDs = "";

            var listbox = document.getElementById("ListPro");
            if (listbox.options.length >= 5) {
                alert("药品对比数量已经满，不能再添加！");
                return false;
            }
            var istrue = 0;


            //            for (var i = 0; i < CheckBoxList.length; i++) {
            //                if (CheckBoxList[i].checked) {
            //                    resultValue = CheckBoxList[i].value;
            //                    tempId = resultValue.split("|")[0];
            //                    tempName = resultValue.split("|")[1];
            //                    hosIDs = hosIDs + tempId + ",";
            //                    hosNames = hosNames + tempName + ",";

            //                    istrue++;
            //                }
            //            }
            for (var i = 0; i < hidCheckArray.length - 1; i++) {

                resultValue = hidCheckArray[i];
                tempId = resultValue.split("|")[0];
                tempName = resultValue.split("|")[1];

                hosIDs = hosIDs + tempId + ",";
                hosNames = hosNames + tempName + ",";

                istrue++;
            }
            if (istrue > 5 && istrue + listbox.options.length >= 5) {
                alert("药品对比数量不得超过" + (5 - listbox.options.length) + "种");
                return false;
            }



            var listbox = document.getElementById("ListPro");
            var hosID = document.getElementById("ProId");
            var hosName = document.getElementById("ProName");
            var arrayName = hosNames.split(',');
            var arrayID = hosIDs.split(',');
            var isUnique = true;
            var temp;

            listbox.length = 0;

            for (m = 0; m < arrayID.length - 1; m++) {

                var listItem = document.createElement("OPTION");

                listItem.text = arrayName[m];

                listItem.value = arrayID[m];

                listbox.add(listItem);
            }
            //            for (m = 0; m < arrayID.length; m++) {
            //                for (n = 0; n < listbox.options.length; n++) {
            //                    if (arrayID[m] == listbox.options[n].value) {
            //                        isUnique = false;
            //                        temp = arrayName[m];
            //                        break;
            //                    }
            //                }
            //            }

            //            if (isUnique == true) {
            //                for (var i = 0; i < arrayName.length; i++) {
            //                    if (!isNull(arrayName[i])) {
            //                        var listItem = document.createElement("OPTION");
            //                        listItem.text = arrayName[i];
            //                        listItem.value = arrayID[i];
            //                        listbox.add(listItem);
            //                    }
            //                }
            //            }
            //            else {
            //                alert("药品" + temp + "已经存在！");
            //                return;
            //            }
            hosID.value = "";
            hosName.value = "";
            for (j = listbox.options.length - 1; j >= 0; j--) {
                hosID.value += listbox[j].value + ",";
                hosName.value += listbox[j].text + ",";
            }

        }

        function deleteCompany() {
            if (!isNull(checkSelected())) {
                var info = checkSelected();
                alert(info);
                return;
            }
            var listbox = document.getElementById("ListPro");
            var companyID = document.getElementById("ProId");
            var companyName = document.getElementById("ProName");
            companyID.value = "";
            companyName.value = "";

            var selectindex = listbox.selectedIndex;

            var hidCheck = document.getElementById("hidCheck");

            if (hidCheck.value.indexOf(listbox[selectindex].value + "|" + listbox[selectindex].text + ",") >= 0) {


                hidCheck.value = hidCheck.value.replace(listbox[selectindex].value + "|" + listbox[selectindex].text + ",", "");

            }

            listbox.remove(selectindex);

            for (j = listbox.options.length - 1; j >= 0; j--) {
                companyID.value = companyID.value + listbox[j].value + ",";
                companyName.value = companyName.value + listbox[j].text + ",";
            }
        }

        function checkSelected() {
            var info;
            var listbox = document.getElementById("ListPro");
            var selectindex = listbox.selectedIndex;
            if (selectindex < 0) {
                info = "请选择要删除的药品！";
                return info;
            }
            return "";
        }

        function isNull(str) {
            var re = /^[ \s]*$/;
            return re.test(str);
        }

        //add by 曹鹏 2011年4月28日17:29:13 实现Gridview点击下一页时，记录用户的前面所选项
        function InsertChecked(owner_obj) {

            var hidCheck = document.getElementById("hidCheck"); //得到隐藏控件

            var ProName = document.getElementById("ProName");
            var ProId = document.getElementById("ProId");

            if (owner_obj.checked) {

                if (hidCheck.value.split(",").length > 5) {

                    alert("药品对比数量不能超过5种！");
                    owner_obj.checked = false;
                    return;

                }
                else {

                    hidCheck.value += owner_obj.value + ","; //如果用户选中checkbox，加到隐藏控件value属性中，值用“，”隔开
                    ProName.value += owner_obj.value.split("|")[1] + ",";
                    ProId.value += owner_obj.value.split("|")[0] + ",";
                }
            }

            else {

                hidCheck.value = hidCheck.value.replace(owner_obj.value + ",", ""); //如果用户取消选中，将checkbox对应值从隐藏控件value之中移除
                ProName.value = ProName.value.replace(owner_obj.value.split("|")[1] + ",", "");
                ProName.value = ProId.value.replace(owner_obj.value.split("|")[0] + ",", "");
            }

        }

        function checkRe() {//当gridview翻页时

            var hidCheck = document.getElementById("hidCheck"); //得到隐藏控件

            var CheckBoxList = document.getElementsByName("chkPro"); //得到gridview中checkbox集合

            for (var i = 0; i < CheckBoxList.length; i++) {//遍历

                if (hidCheck.value.indexOf(CheckBoxList[i].value) >= 0) {//判断是否存在

                    CheckBoxList[i].checked = true; //选中

                }

            }

        }
        function recover() {

            var hidCheck = document.getElementById("hidCheck"); //得到隐藏控件

            var listbox = document.getElementById("ListPro");

            var array = hidCheck.value.split(",");

            listbox.length = 0;

            for (var m = 0; m < array.length - 1; m++) {

                var listItem = document.createElement("OPTION");

                listItem.text = array[m].split("|")[1];

                listItem.value = array[m].split("|")[0];

                listbox.add(listItem);

            }

        }
    </script>

    <style type="text/css">
        .style5
        {
            width: 983px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table class="querylist">
        <tr>
            <td>
                <asp:Label ID="lblQueryCondition" runat="server" Text="通用名："></asp:Label>
            </td>
            <td align="left">
                <asp:TextBox ID="txtProName" runat="server"></asp:TextBox>
            </td>
            <td>
                生产企业：
            </td>
            <td align="left">
                <asp:TextBox ID="txtCompanyName_SC" runat="server"></asp:TextBox>
            </td>
            <%--<td style="width: 60px">
                <asp:Label ID="Label3" runat="server" Text="生产企业："></asp:Label>
            </td>
            <td align="left" class="style13">
                <asp:TextBox ID="txtComPs" runat="server"></asp:TextBox>
            </td>--%>
            <%--<td>
                <asp:Label ID="Label4" runat="server" Text="采购类型："></asp:Label>
            </td>
            <td align="left">
                <asp:DropDownList ID="dropSortSource" runat="server" Height="19px" Width="120px">
                    <asp:ListItem Value="-1">全部</asp:ListItem>
                    <asp:ListItem Value="3">2010基本药物</asp:ListItem>
                    <asp:ListItem Value="5">2010限价品种</asp:ListItem>
                    <asp:ListItem Value="6">2010补充药品</asp:ListItem>
                </asp:DropDownList>
            </td>--%>
            <td>
                <hz:HzButton ID="btnQery" runat="server" CssClass="btn" OnClick="btnQery_Click" Text="查  询" />
            </td>
        </tr>
    </table>
    <table class="querylist">
        <tr>
            <td class="style5">
                <%--选择药品：--%>
            </td>
            <%--<td class="style4">&nbsp;</td>--%></tr>
        <tr>
            <td class="style5">
                <div>
                    <font color="red">提示：药品对比数量不能超过5种！</font></div>
                <asp:GridView ID="gvwProList" runat="server" CssClass="mainlist" AutoGenerateColumns="False"
                    DataKeyNames="ProcureCatalogID" EmptyDataText="暂无符合条件的数据！" Width='100%'>
                    <Columns>
                        <asp:TemplateField>
                            <HeaderTemplate>
                                <%-- <input id="chkAllPro" name="chkAllPro" type="checkbox" onclick="SelectAllCheckboxes(this,'gvwProList','chkAllPro');" />--%>
                                请选择
                            </HeaderTemplate>
                            <ItemTemplate>
                                <input id="chkPro" name="chkPro" type="checkbox" <%-- onclick="InsertChecked(this);chkChecked(this,'gvwProList','chkAllPro');"--%>
                                    onclick="InsertChecked(this);" value='<%# Eval("ProcureCatalogID") %>|<%# Eval("ProductName") %>'>
                                </input>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <%--流水号该用序号
                        张雄 modify 2011.4.21--%>
                        <asp:TemplateField HeaderText="序号">
                            <ItemTemplate>
                                <%#Container.DataItemIndex + 1 + AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1) %>
                                <%--<asp:Label ID="lblAreaName" runat="server" Text='<%# Eval("ProcureCatalogID") %>'></asp:Label>--%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="通用名">
                            <ItemTemplate>
                                <asp:Label ID="lblAreaName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="剂型">
                            <ItemTemplate>
                                <asp:Label ID="lblMedicineModel" runat="server" Text='<%# Eval("MedicineModelName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="采购规格">
                            <ItemTemplate>
                                <asp:Label ID="lblPack" runat="server" Text='<%# Eval("Pack") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="采购单位">
                            <ItemTemplate>
                                <asp:Label ID="lblUnit" runat="server" Text='<%# Bind("Unit") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="生产企业">
                            <ItemTemplate>
                                <asp:Label ID="lblCompanyName_SC" runat="server" Text='<%#Eval("CompanyName_SC") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="采购类型">
                            <ItemTemplate>
                                <asp:Label ID="lblSortSource" runat="server" Text='<%#HZ.Supervise.Web.Function.FormatDrugSource(Eval("SortSource"))%>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="采购单价（元）">
                            <ItemTemplate>
                                <asp:Label ID="lblPrice" runat="server" Text='<%# Bind("ProcurePrice") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
                    CustomInfoStyle="hide">
                </webdiyer:AspNetPager>
                <input id="hidCheck" name="hidCheck" type="hidden" runat="server" />
            </td>
            <%--            <td class="style4">
                <p><input type="button" id="btnIn" value="加入对比" class="btn" onclick="insertCompanyInfo();" /></p><p><input type="button" id="btnOut"  value="删除对比" class="btn" onclick="deleteCompany();" /></p><p><input type="button" id="btnOk" value="确认对比" class="btn" onclick="return addAreaInfo();" /></p>
                </td>--%>
        </tr>
        <tr>
            <td class="style5">
                <input id="btnIn" class="btn" onclick="insertCompanyInfo();" type="button" value="加入对比" />&nbsp;&nbsp;&nbsp;
                <input id="btnOut" class="btn" onclick="deleteCompany();" type="button" value="删除对比" />&nbsp;&nbsp;&nbsp;
                <input id="btnOk" class="btn" onclick="return addAreaInfo();" type="button" value="确认对比" />
            </td>
            <%--<td>1</td>--%>
        </tr>
        <tr>
            <td class="style5">
                <asp:ListBox ID="ListPro" runat="server" Height="106px" Width="100%"></asp:ListBox>
                <input id="ProName" type="hidden" name="ProName" runat="server" />
                <input id="ProId" type="hidden" name="ProId" runat="server" />
            </td>
            <%--<td class="style4"></td>--%></tr>
    </table>

    <script type='text/javascript'>
        checkRe(); recover();
    </script>

    </form>
</body>
